﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

using Microsoft.Practices.Unity;
using Marking.Dashboard.Services;
using Marking.Dashboard.Services.Locals;
using Marking.Dashboard.Services.Remotes;

namespace Marking.Dashboard.Infrastructures
{
    /// <summary>
    /// Unity工具。
    /// </summary>
    public static class UnityHelper
    {
        private static IUnityContainer _Container = new UnityContainer();

        public static IUnityContainer Container
        {
            get { return UnityHelper._Container; }
        }

        public static void Init()
        {
            if (IsRunInFileSystem())
            {
                _Container.RegisterType<ISalesService, LocalSalesService>();
                _Container.RegisterType<IStockService, LocalStockService>();
                _Container.RegisterType<ILoginService, LocalLoginService>();
            }
            else
            {
                _Container.RegisterType<ISalesService, RemoteSalesService>();
                _Container.RegisterType<IStockService, RemoteStockService>();
                _Container.RegisterType<ILoginService, RemoteLoginService>();
            }
        }

        private static bool IsRunInFileSystem()
        {
            return !HtmlPage.Document.DocumentUri.AbsoluteUri.StartsWith("http");
        }
    }
}
